]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/Tests/Unit Tests/ResourceRecordTest.m
mDNSResponder-1096.40.7.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / Tests / Unit Tests / ResourceRecordTest.m
1 /*
2 * Copyright (c) 2017-2018 Apple Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "mDNSEmbeddedAPI.h"
18 #include "DNSCommon.h"
19 #import <XCTest/XCTest.h>
20
21 @interface ResourceRecordTest : XCTestCase
22 {
23 }
24 @end
25
26 @implementation ResourceRecordTest
27
28 - (void)setUp
29 {
30 }
31
32 - (void)tearDown
33 {
34 }
35
36 - (void)testTXTSetup
37 {
38 AuthRecord authRec;
39 mDNS_SetupResourceRecord(&authRec, mDNSNULL, mDNSInterface_Any, kDNSType_TXT, kStandardTTL, kDNSRecordTypeShared, AuthRecordAny,mDNSNULL, mDNSNULL);
40 XCTAssertEqual(authRec.resrec.rrtype, kDNSType_TXT);
41 XCTAssertEqual(authRec.resrec.RecordType, kDNSRecordTypeShared);
42 XCTAssertEqual(authRec.resrec.rdata->MaxRDLength, sizeof(RDataBody));
43 }
44
45 - (void)testASetup
46 {
47 AuthRecord authRec;
48 mDNS_SetupResourceRecord(&authRec, mDNSNULL, mDNSInterface_Any, kDNSType_A, kHostNameTTL, kDNSRecordTypeUnique, AuthRecordAny, mDNSNULL, mDNSNULL);
49
50 XCTAssertEqual(authRec.resrec.rrtype, kDNSType_A);
51 XCTAssertEqual(authRec.resrec.RecordType, kDNSRecordTypeUnique);
52 // Add more verifications
53 }
54
55 - (void)testOPTSetup
56 {
57 AuthRecord opt;
58 mDNSu32 updatelease = 7200;
59
60 // Setup the OPT Record
61 mDNS_SetupResourceRecord(&opt, mDNSNULL, mDNSInterface_Any, kDNSType_OPT, kStandardTTL, kDNSRecordTypeKnownUnique, AuthRecordAny, mDNSNULL, mDNSNULL);
62
63 // Verify the basic initialization is all ok
64
65 opt.resrec.rrclass = NormalMaxDNSMessageData;
66 opt.resrec.rdlength = sizeof(rdataOPT); // One option in this OPT record
67 opt.resrec.rdestimate = sizeof(rdataOPT);
68 opt.resrec.rdata->u.opt[0].opt = kDNSOpt_Lease;
69 opt.resrec.rdata->u.opt[0].u.updatelease = updatelease;
70
71 // Put the resource record in and verify everything is fine
72 #if 0
73 mDNSu8 data[AbsoluteMaxDNSMessageData];
74 mDNSu8 *p = data;
75 mDNSu16 numAdditionals;
76
77 p = PutResourceRecordTTLWithLimit((DNSMessage*)&data, p, &numAdditionals, &opt.resrec, opt.resrec.rroriginalttl, data + AbsoluteMaxDNSMessageData);
78 #endif
79 }
80
81 // Repeat with bad data to make sure it bails out cleanly
82
83 #if 0
84 - (void)testPerformanceExample {
85 // This is an example of a performance test case.
86 [self measureBlock:^{
87 // Put the code you want to measure the time of here.
88 }];
89 }
90 #endif
91
92 @end